package com.chat.datea.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.greendao.Collect;

import java.util.ArrayList;

/**
 * Created by YanBinXie on 15/11/5.
 */
public class CollectAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<Collect> collects;

    public CollectAdapter(Context context, ArrayList<Collect> collects) {
        this.context = context;
        this.collects = collects;
    }

    @Override
    public int getCount() {
        return collects != null && collects.size() > 0 ? collects.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return collects != null && collects.size() > 0 ? collects.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return collects != null && collects.size() > 0 ? position : 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.collect_list_item, null);
            holder.music_name = (TextView) convertView.findViewById(R.id.music_name);
            holder.music_singer = (TextView) convertView.findViewById(R.id.music_singer);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.music_name.setText(collects.get(position).getName());
        holder.music_singer.setText(collects.get(position).getSinger());
        return convertView;
    }

    class ViewHolder {
        TextView music_name, music_singer;

    }
}
